package com.novasoftware.novagooglemap.wibget.gmap;

import java.util.ArrayList;
import java.util.Iterator;

import android.R.bool;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.Point;
import android.util.Log;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class LineOverlay extends Overlay {
	
	public ArrayList<GeoPoint> geoArrayList = new ArrayList<GeoPoint>();
	
	public void AddPoint(GeoPoint point)
	{
		geoArrayList.add(point);
	}
	
	public void RemovePoint(GeoPoint point)
	{
		if(geoArrayList.contains(point))
			geoArrayList.remove(point);
	}
	
	public void draw(Canvas canvas, MapView mapView, boolean shadow) 
    {
        super.draw(canvas, mapView, shadow);

        canvas.drawColor(Color.RED);
        Paint mPaint = new Paint();
        mPaint.setDither(true);
        mPaint.setStyle(Style.FILL_AND_STROKE);
        mPaint.setColor(Color.RED);
        mPaint.setAlpha(9);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setStrokeJoin(Paint.Join.ROUND);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setStrokeWidth(2);

        Path path = new Path();

        Projection projection = mapView.getProjection();

		for(int j = 0; j < geoArrayList.size(); j++) 
        {
            Iterator<GeoPoint> it = geoArrayList.iterator();
            while(it.hasNext()) 
            {
            	
                GeoPoint arrayListGeoPoint = it.next();

                Point currentScreenPoint = new Point();
                projection.toPixels(arrayListGeoPoint, currentScreenPoint);

                if(j == 0)
                    path.moveTo(currentScreenPoint.x, currentScreenPoint.y); 
                else
                    path.lineTo(currentScreenPoint.x, currentScreenPoint.y);
            }                 
        }
        canvas.drawPath(path, mPaint);
    }   
	
	public void draw(MapView mapView,boolean shadow)
	{
		Canvas canvas = new Canvas();
		draw(canvas, mapView,shadow);
	}
}
